package com.example.administrator.easy.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.example.administrator.easy.R;
import com.example.administrator.easy.detailxinfo.DetailBean;
import com.example.administrator.easy.detailxinfo.DetailFuli;

import org.xutils.x;

import java.util.List;

/**
 * Created by jingsheng on 2016/11/15.
 */

public class ShopAdapter extends BaseAdapter {//
    private List<DetailBean> list;
    private Context context;

    public ShopAdapter(List<DetailBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ShopViewHodler vh;

        if (convertView==null){
            vh=new ShopViewHodler();
            convertView=View.inflate(context,R.layout.shop_item,null);

            vh.setView(convertView);
            convertView.setTag(vh);

        }else {
            vh= (ShopViewHodler) convertView.getTag();
        }
        x.image().bind(vh.imageView,list.get(position).urlCount);
        vh.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context,DetailFuli.class);
                intent.putExtra("content",list.get(position).count);
                intent.putExtra("id",list.get(position).urlUser);
                intent.putExtra("img",list.get(position).urlCount);
                intent.putExtra("title",list.get(position).userName);
                context.startActivity(intent);
            }
        });
        return convertView;
    }
    class ShopViewHodler{
        private ImageView imageView;
        private void setView(View view){
            imageView= (ImageView) view.findViewById(R.id.shop_iv_lv);
        }

    }
}
